package com.taxigang.client.uibinder;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.Session;
import com.taxigang.client.facebook.FacebookApi;

public class TaxiGangHeader extends Composite {

	private static TaxiGangHeaderUiBinder uiBinder = GWT
			.create(TaxiGangHeaderUiBinder.class);

	interface TaxiGangHeaderUiBinder extends UiBinder<Widget, TaxiGangHeader> {
	}
	
//	@UiField
//	static MenuItem feedbackMenuItem;
//	
//	@UiField
//	MenuItem loginMenuItem;
//	
//	@UiField
//	MenuItem myTaxiGangsMenuItem;
//	
//	@UiField
//	MenuBar menuBar;
//	
	
	
	@UiField
	Button myTaxiGangsMenuButton;
	
	@UiField
	Button agbButton;
	
	@UiField
	Button manualFBButton;
	
	@UiField
	Button contactButton;
	
	AGB agb = new AGB();
	ContactForm contactForm = new ContactForm();
	
//	@UiField
//	Image gap0;
//	
//	@UiField
//	Image gap1;
//	
//	@UiField
//	Image gap2;
	
	@UiField
	Image headerLogoImage;
		
	@UiField
	Panel 	buttonsPanel;
//	@UiField
//	DivElement fbLoginButton;
	

	public TaxiGangHeader() {
		initWidget(uiBinder.createAndBindUi(this));
		headerLogoImage.setUrl(MyResources.INSTANCE.logo().getSafeUri());

//		gap0.setUrl("images/gap.jpg");
//		gap1.setUrl("images/gap.jpg");
//		gap2.setUrl("images/gap.jpg");
//		feedbackMenuItem.setText(TaxiGangCreator.taxiGangConstants.feedback());
//		feedbackMenuItem.setCommand(new Command() {
//			
//			@Override
//			public void execute() {
//				taxiGangRoute.show(PanelType.FEEDBACK);
//			}
//		});
//		
//		//loginMenuItem
//		loginMenuItem.setText(TaxiGangCreator.taxiGangConstants.sigin());
//		loginMenuItem.setCommand(new Command() {
//			
//			@Override
//			public void execute() {
//				taxiGangRoute.show(PanelType.LOGIN);
//			}
//		});
//		
//		//myTaxiGangsMenuItem
//		myTaxiGangsMenuItem.setText(TaxiGangCreator.taxiGangConstants.myTaxiGang());
//		myTaxiGangsMenuItem.setCommand(new Command() {
//			
//			@Override
//			public void execute() {
//				TaxiGangPresenter.getInstance().myTaxiGang(true);
//			}
//		});
		
		manualFBButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				FacebookApi.fbLogin();
				
				
			}
		});
		
		myTaxiGangsMenuButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				TaxiGangPresenter.getInstance().myTaxiGang(true);
				
				
			}
		});
		
		agbButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				Widget source = (Widget) event.getSource();
	            int left = source.getAbsoluteLeft() - 1000;
	            int top = source.getAbsoluteTop() + 100;
	            agb.setPopupPosition(left, top);

				agb.show();
				
				
			}
		});
		contactButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				Widget source = (Widget) event.getSource();
	            int left = source.getAbsoluteLeft() - 100;
	            int top = source.getAbsoluteTop() + 100;
	            contactForm.setPopupPosition(left, top);

	            contactForm.show();
				
				
			}
		});
		//fbLoginButton.setInnerHTML("<fb:login-button scope=\"publish_stream\" />");
		//fbLoginButton.setInnerHTML("<fb:login-button />");

				
	}

		
	public void showMenu(){
		buttonsPanel.setVisible(true);

		myTaxiGangsMenuButton.setText("My Taxigang");
		if (Session.getInstance().getLocale().equals("de")){
			agbButton.setVisible(true);
			agbButton.setText("AGB");
		}
		manualFBButton.setText("Login");
		contactButton.setText("Contact");
		manualFBButton.setVisible(false);
		
	}


	public void showLoginButton(boolean show) {
		manualFBButton.setVisible(show);
		
	}
}
